package org.orzeszek.transfer.gui;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.JFrame;

import org.orzeszek.transfer.Settings;

/**
 * The main pain for the application.
 * 
 * @author Michael Gierasimiuk
 */
public class ApplicationWindow extends JFrame
{
  public static final int DEFAULT_W = 700;
  public static final int DEFAULT_H = 500;

  public static final String TITLE = "Orzeszek Transfer";
  
  /**
   * /** Creates a new {@link ApplicationWindow} instance.
   */
  public ApplicationWindow()
  {
    this.setLayout( new GridBagLayout() );
    this.setTitle( TITLE );
  }

  public void destroy()
  {

  }

  /**
   * Updates the given {@link Settings} implementation with user
   * options by displaying a dialog.
   * 
   * @param settings the settings to update via a dialog.
   */
  public void showSettingsDialog( Settings settings )
  {
    SettingsWindow window = new SettingsWindow( this );

    window.initialize( settings );
    window.setSize( SettingsWindow.DEFAULT_W, SettingsWindow.DEFAULT_H );
    window.center();
    window.setVisible( true );
  }

  /**
   * Positions the {@link ApplicationWindow} in the center of the screen. This
   * method should be called once the size of the frame has been set.
   */
  public void centerWindow()
  {
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    int w = this.getSize().width;
    int h = this.getSize().height;

    int x = ( screen.width - w ) / 2;
    int y = ( screen.height - h ) / 2;

    this.setLocation( x, y );
  }
}
